<form id="changephone_new" method="post" enctype="multipart/form-data">
    <div class="row row1">
        <label class="col-sm-2 control-label">手机号：</label>
        <div class="col-sm-5">
            <input type="text" class="form-control" name="phone" id="phone" placeholder="请输入手机号">
        </div>
        <a href="JavaScript:;" id="yzm" class="go" style="margin-left:20px;text-decoration:none;display:inline-block;width:120px;border-radius:5px;line-height: 30px;height: 30px;background-color: dodgerblue;color:#fff;text-align: center;font-size: 14px">
            获取验证码
        </a>
    </div>
    <br/>
    <div class="row row1">
        <label class="col-sm-2 control-label">验证码：</label>
        <div class="col-sm-5">
            <input type="text" class="form-control" name="usercode" placeholder="请输入验证码">
        </div>
    </div>
</form>
<script>
    var intv2;
    $('#yzm').click(function () {
        var phone = $('#phone').val().trim();
        var rule = /^1(3|4|5|7|8)\d{9}$/;
        if(!(rule.test(phone))){
            alert("手机号码有误，请重填");
        }else{
            if($(this).hasClass('go')){
                $('#yzm').css({'background-color':'#ccc'});
                $('#yzm').text('59秒后重新获取');
                $('#yzm').removeClass('go');
                intv2 = setInterval("timego2()",1000);
                $.ajax({
                    url:'admin/Admin/getPhoneCode',
                    data:'type=2'+'&phone='+phone,
                    type:'POST',
                    dataType:'JSON',
                    success:function(returndata){
                        if (returndata.status != 200) {
                            $.TeachDialog({
                                content: returndata.msg
                            });
                        }
                    },
                    error: function () {
                        $.TeachDialog({
                            content: '系统异常，请联系管理员'
                        });
                    }
                });
            }else{
                return;
            }
        }

    });
    function timego2() {
        var m = parseInt($('#yzm').text());
        var nm = m-1;
        if(nm > 0){
            $('#yzm').text(nm+'秒后重新获取');
        }else{
            $('#yzm').css({'background-color':'dodgerblue'});
            $('#yzm').text('获取验证码');
            $('#yzm').addClass('go');
            clearInterval(intv2);
            return;
        }

    }
</script>

